Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

try to use "toJSON" method before converting named objects to string #10

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

vl-skripkin
Copy link

@vl-skripkin vl-skripkin commented Sep 9, 2019

Nuxt uses devalue to pass vuex state from server- to client-side. And at the moment devalue converts simple objects to "json format" as is, key by key. But sometimes it is usefull to make some changes in a data before this conversion, "toJSON" method should be used for this.

For example, I create data models with default empty values on server-side, but due to some logic of my app the models were left as is, with default values, so there is no need to pass all keys of empty models to client-side, because I can create new empty models on client-side. So in this case the data model should have "toJSON" method, and devalue should call it. The method may look like this:

toJSON ()
{
	return is_new(this) ? {} : this;
}

Copy link
Member

@manniL manniL left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't include the version bump please

package.json Outdated Show resolved Hide resolved
@pi0
Copy link
Member

pi0 commented Sep 10, 2019

Thanks for PR. Please make a proper description of this change. An example of the edge case it is fixing, etc. Also would be a good idea to attempt fixing this issue at mainstream: https://github.com/Rich-Harris/devalue

If it not works for everyone (a nuxt users requirement) we can then add patch here.

@atinux atinux added the pending label Nov 10, 2020
Base automatically changed from master to main February 1, 2021 15:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants